package com.qf.controller;

import cn.hutool.core.lang.tree.Tree;
import com.qf.entity.MdItemType;
import com.qf.entity.MdItemTypeVO;
import com.qf.service.MdItemTypeService;
import com.qf.util.R;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * ==== 勤能补拙 ====
 *
 * @author dzz
 * @date 2025/4/21
 * <p>
 * ==== 行稳致远 进而有为 ====
 */
@Log4j2
@RestController
@RequestMapping("/md")
public class MdItemTypeController {

    @Autowired
    private MdItemTypeService mdItemTypeService;
    /**
     * 获取物料产品分类树形菜单V1
     */
    @GetMapping("/item/type/tree1")
    public R getItemTypeTreeV1(){
        log.info("获取物料产品分类树形菜单V1");
        List<MdItemTypeVO> mdItemTypeVO = mdItemTypeService.getMdItemTypeTreeV1();
        return R.ok(mdItemTypeVO);
    }
    //先查顶级分类
    //再查子分类
    //递归查询子分类
    /**
     * 获取物料产品分类树形菜单V2
     */
    @GetMapping("/item/type/tree2")
    public R getItemTypeTreeV2(){
       log.info("获取物料产品分类树形菜单V2");
        List<MdItemTypeVO> mdItemTypeVO = mdItemTypeService.getMdItemTypeTreeV2();
        return R.ok(mdItemTypeVO);
    }
    /**
     * 获取物料产品分类树形菜单V3
     */
    @GetMapping("/item/type/tree3")
    public R getItemTypeTreeV3(){
        log.info("获取物料产品分类树形菜单V3");
        List<Tree<String>> mdItemTypeVO = mdItemTypeService.getMdItemTypeTreeV3();
        return R.ok(mdItemTypeVO);
    }
    /**
     * 根据主键id删除物料产品分类
     */
    @GetMapping("/item/type/del/{id}")
    public R delItemTypeById(@PathVariable("id") Integer id){
        log.info("根据主键id删除物料产品分类");
        int i = mdItemTypeService.deleteMdItemTypeById(id);
        if(i>0){
            return R.ok("删除成功");
        }
        return R.fail("删除失败");
    }
    /**
     * 添加物料产品分类
     */
    @GetMapping("/item/type/add")
    public R addItemType(MdItemType mdItemType){
        log.info("添加物料产品分类");
        int i = mdItemTypeService.addItemType(mdItemType);
        if(i>0){
            return R.ok("添加成功");
        }
        return R.fail("添加失败");
    }

}
